package com.springbootmybatis.sql;

import com.springbootmybatis.pojo.Book;
import org.apache.ibatis.jdbc.SQL;

public class SqlContext {
	public String searchBookSql(Book book){
		return new SQL(){
			{
				SELECT ("*");
					FROM("book");
				if (book.getName()!=null&&book.getName()!="") {
					WHERE("name like '%' #{name} '%'");
				}
				if (book.getCategory()!=null&&book.getCategory()!="") {
					WHERE("category = #{category}");
				}
				if (book.getAuthor()!=null&&book.getAuthor()!="") {
					WHERE("author = #{author}");
				}
			}
		}.toString();
	}

}
